﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Profile.aspx.cs" Inherits="ExaminationSys.Profile"   MasterPageFile="~/View/Share/Index.Master" %>
<%@ Import Namespace="ExaminationSys.DataAccess.Entity" %>
<%@ Import Namespace="Ext.Net" %>
<%@ Import Namespace="ExaminationSys.Helper" %>
<%@ Import Namespace="Ext.Net.Utilities"%>
<%@ Import Namespace="System.Collections.Generic" %>



<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<asp:Content ID="head" ContentPlaceHolderID="head" runat="server">
<link type="text/css" rel="stylesheet" media="all" href="css/others.css" />
<style type="text/css">
    .current a:hover
    {
        color: #333333;
        text-decoration: none;
        cursor: default;
    }
  
   .box{width:100%;text-align:center;}
.box .fixie{width:320px;margin:0 auto;text-align:left;}
</style>
 <script src="js/jquery.js" type="text/javascript"></script>

   <script type="text/javascript">
       $(function () {
           $("#btnSignOut").click(function () {
               var answer = confirm("是否退出?");
               if (answer) {

                   $.ajax({
                       type: "GET",
                       cache: false,
                       contentType: "application/json",
                       url: "ashx/StudentSignOutHandler.ashx",
                       dataType: 'json',
                       data: null,
                       async: false,
                       success: function (data) {
                           if (data != '200') {
                               alert('操作失败'); return false;
                           }
                           else {
                               var host = window.location.host;
                               window.location.href = "http://" + host + "/Index.aspx";
                           }
                       }
                   });
               }
           });
       });
</script>
<script runat="server">
    public void BtnCancel_Click(object sender, DirectEventArgs e)
    {
        Response.Redirect("Index.aspx");
    }

    public void BtnOk_Click(object sender, DirectEventArgs e)
    {
        var nickName = TB_StudentNickName.Text;
        if (string.IsNullOrEmpty(nickName))
        {
            MessageBoxHelper.ShowError("昵称不能为空");
            return;
        }
        var email = TB_Email.Text;
        if (string.IsNullOrEmpty(email))
        {
            MessageBoxHelper.ShowError("Email不能为空");
            return;
        }
        var noticeValue = NF_NoticeValue.Number;
        
        var selectItem = SelectBoxNoticeType.SelectedItem;
        var selectType = selectItem == null ? -1 : Convert.ToInt32(selectItem.Value);

        if (selectType == -1)
        {
            MessageBoxHelper.ShowError("请选择提醒方式");
            return;
        }

        var loginInfo = Session["StudentInfo"] as Student;
        if (loginInfo != null)
        {
            /*
              <ext:ListItem  Text="按星期" Value="1"  ></ext:ListItem>
              <ext:ListItem  Text="间隔天数" Value="2"></ext:ListItem>
             */
            loginInfo.Title = nickName;
            loginInfo.Email = email;
            loginInfo.NoticeType = selectType;
            loginInfo.NoticeValue = Convert.ToInt32(noticeValue);
           var success= ProxyStudent.Update(loginInfo);

           if (success)
           {
               Session["StudentInfo"] = loginInfo;
                MessageBoxHelper.ShowInfo("保存成功!");
                return;
                // Response.Redirect("~/Account/Login.aspx");
            }
           else
           {
               MessageBoxHelper.ShowError("保存失败");
               return;
           }
        }
        else
        {
            MessageBoxHelper.ShowError("登录状态失效,请注销后重新登录");
            return;
            
        }
    }
</script>
</asp:Content>
<asp:Content ID="headerContent" ContentPlaceHolderID="HeaderHolder" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server">
       
    </ext:ResourceManager>
    <div class="h-top">
        <div class="logo fl"><img src="images/logo.gif" alt="上海交通大学英语学习中心"/></div>
        <div class="navandsearch fr">
            <ul class="nav">
                  <li><a class="nav-home" href="Index.aspx" title="首页">首页</a></li>
                <li><a class="nav-info" href="Newslist.aspx" title="信息快递">信息快递</a></li>
                <li><a class="nav-help" href="Help.aspx" title="帮助">帮助</a></li>
            </ul>
            <div class="h-search">
                <input id="textKey" class="text" name="" type="text" value="搜索信息" />
                <input id="btnSearch" class="publicbtn btn-search" name="" type="button" value="搜索" />
            </div>
        </div><!--end navandsearch-->
    </div>
    <div class="h-banner"><img src="images/pic/pic02.jpg" width="966" height="308"/></div>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentHolder" runat="server">

<div class="side">
        	<div class="box203">
            	<div class="titles"><img src="images/tit_xx.gif" alt="用户信息"/></div>
            	<div class="conts side-login-on">
                	<p class="tit"><span class="red">欢迎您！</span><span><%=LoginName%></span>同学</p>
                	<ul>
                    	<li><a href="javascript:void(0);">个人资料</a></li>
                        <li><a href="ChangePassword.aspx">密码修改</a></li>
                    </ul>
                    
                    <div class="button">                    
                    <a href="StudyCenter.aspx" id="btnStudycenter"><span style="border:1px solid #e3e3e3;color:red;padding:3px;margin:18px">学习中心</span></a>
                    <input id="btnSignOut" class="publicbtn btn-logout" name="" type="button"  value="退出"/></div>	
                </div>
                <div class="box-bbg"></div>
            </div>
            <div class="side-bang">
                <ul class="red">
                    <li class="li_1"><%=DiligentRank %></li>
                    <li class="li_2"><%=ChampionRank%></li>
                </ul>
            </div>
            
            <div class="login-on-info">
            	<h3><span>登录信息</span></h3>
                <p> 您共登陆了 <b><span class="red"><%= LoginCount%></span> 次</b></p>
                <p class="his"> 您的上次登陆时间为：<span class="red"><%=LastLoginTime%></span></p>
            </div>
           
        </div><!--end side-->
    <!--end side-->


    <div class="contents">
       <div class="other-titles">
            <span class="subtit">个人资料</span>
            <div class="box" >
                    <div class="fixie">
                     <ext:FormPanel 
                   runat="server" ID="FormPanel1" 
            Border="false"
            Icon="Application"
            AutoHeight="true" 
            Width="300" 
            ButtonAlign="Center"
             Resizable="false"          
            Modal="true"
                   >
                    <Items>
                      <ext:TextField ID="TB_StudentNo"     runat="server" FieldLabel="学号" />  
                      <ext:TextField ID="TB_StudentName"     runat="server" FieldLabel="姓名" />  
                      <ext:TextField ID="TB_StudentNickName" AllowBlank="false"   runat="server" FieldLabel="昵称" />  
                      <ext:TextField ID="TB_StudentCollege"   runat="server" FieldLabel="学院" />  
                      <ext:TextField ID="TB_StudentMajor"   runat="server" FieldLabel="专业" /> 
                      <ext:TextField ID="TB_StudentClass"   runat="server" FieldLabel="班级" /> 
                      <ext:TextField ID="TB_Email" AllowBlank="false" Vtype="email"    runat="server" FieldLabel="电子邮件" /> 
                       <ext:SelectBox
                        ID="SelectBoxNoticeType"
                        runat="server" 
                        FieldLabel="提醒方式"
                        EmptyText="选择提醒方式...">
                        <Items>
                            <ext:ListItem  Text="按星期" Value="1"  ></ext:ListItem>
                            <ext:ListItem  Text="间隔天数" Value="2"></ext:ListItem>
                        </Items>
                    </ext:SelectBox>
                        <ext:NumberField 
                        ID="NF_NoticeValue" 
                        runat="server" 
                        FieldLabel="提醒间隔" AllowBlank="false" 
                        MinValue="1"
                        MaxValue="7"
                        AllowDecimals="true"
                        DecimalPrecision="1"
                        Step="1"
                        />
                    </Items>
                   <Buttons>
                        <ext:Button
                            ID="BtnOK"
                            runat="server" 
                            Text="保存"  
                            Disabled="true"
                            FormBind="true">
                            <DirectEvents>
                                    <Click OnEvent="BtnOk_Click">
                                        <EventMask ShowMask="true" Msg="正在处理..." MinDelay="500" />
                                    </Click>
                        
                                </DirectEvents>
                            <Listeners>
                             
                                <Click  Handler="if (!#{TB_StudentNickName}.validate() || !#{TB_Email}.validate()||!#{NF_NoticeValue}.validate()) {
                                Ext.Msg.show({title:'提示信息',msg:'昵称<br/>Email<br/>提醒间隔 <br/>必须填写',buttons:Ext.Msg.OK,icon:Ext.MessageBox.WARNING}); return false;}" />
                            </Listeners>
                        </ext:Button>
                        <ext:Button ID="BtnCancel" runat="server" Text="返回" >
                            <Listeners>
                                <Click Handler="javascript:window.history.go(-1);"></Click>
                            </Listeners>
                        </ext:Button>
                    </Buttons>
                    <Listeners>
                        <ValidityChange Handler="#{BtnOK}.setDisabled(!valid);" />
                    </Listeners>
                </ext:FormPanel> 
                 </div>
            </div>
        </div>
    </div>
    <!--end contents-->
</asp:Content>
